home *** CD-ROM | disk | FTP | other *** search
/ 130 MIDI Tool Box / 130 MIDI Tool Box.iso / mpu401c / getpat.c < prev    next >
C/C++ Source or Header  |  1986-11-02  |  2KB  |  88 lines

  1. /* Copyright (C) 1986 by M. J. Shannon, Jr.
  2. ** Permission to distribute for non-commercial uses granted as long as this
  3. ** notice is retained.  Violators will be prosecuted.
  4. */
  5.  
  6. #include    <stdio.h>
  7. #include    "mpu/mpu.h"
  8.  
  9. void getavoice();
  10.  
  11. unsigned char dump1voice[] =
  12. {
  13.     0xF0,    /* System Exclusive */
  14.     0x43,    /* ID: Yamaha */
  15.     0x20,    /* substatus w/channel 0 */
  16.     0x03,    /* format (1 voice) */
  17.     0xF7    /* EOX */
  18. };
  19.  
  20. unsigned char read_buf[256];    /* a buffer to read into */
  21.  
  22. int
  23. main(argc, argv, envp)
  24. int argc;
  25. char **argv;
  26. char **envp;
  27. {
  28.     char *vers_string;
  29.  
  30.     /* reset the MPU */
  31.     mpu_reset();
  32.     /* get the firmware version/revision */
  33.     vers_string = mpu_id();
  34.     /* show it to the user */
  35.     printf("MPU: %s\n", vers_string);
  36.     /* enable various options */
  37.     mpu_put(SWE_HEXCL);
  38.     mpu_put(SWE_DATAINSTOP);
  39.     mpu_put(SWE_TIME);
  40.     /* and get patches until the user gives up */
  41.     for (;;)
  42.         getavoice();
  43.     /* return success to DOS */
  44.     return (0);
  45. }
  46.  
  47. void
  48. getavoice()
  49. {
  50.     int length;
  51.     FILE *fp;
  52.     char s[256];
  53.  
  54.     /* Tell the DX-100 to dump a voice */
  55.     mpu_sexcl(dump1voice);
  56.     /* But it just echoes the message, so ignore it */
  57.     length = mpu_read(&read_buf[0]);
  58. getfile:;
  59.     /* ask for a filename to store the patch into */
  60.     printf("File name:");
  61.     gets(s);
  62.     /* to get out, just hit CR */
  63.     if (s[0] == '\0')
  64.         exit(0);
  65.     /* create the file for binary i/o */
  66.     fp = fopen(s, "wb");
  67.     /* complain if we couldn't */
  68.     if (!fp)
  69.     {
  70.         printf("Couldn't create <%s>!\n", s);
  71.         goto getfile;
  72.     }
  73.     /* prompt the user */
  74.     printf("Press voice selector now.\n");
  75.     /* read until we get something */
  76.     while ((length = mpu_read(&read_buf[0])) == 0)
  77.         /* tell user we didn't get anything */
  78.         printf("Waiting...\n");
  79.     /* tell user how much we got */
  80.     printf("Got %d bytes.\n", length);
  81.     /* write it out */
  82.     fwrite(read_buf, length, 1, fp);
  83.     /* close the file */
  84.     fclose(fp);
  85.     /* and confirm to user */
  86.     printf("Written to <%s>!\n", s);
  87. }
  88.